package com.longcai.piaojia.activity;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.longcai.piaojia.BaseApplication;
import com.longcai.piaojia.R;
import com.longcai.piaojia.conn.FeedBackSetGet;
import com.longcai.piaojia.dialog.WarnningDialog;
import com.longcai.piaojia.util.MyToast;
import com.zcx.helper.bound.BoundView;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.util.UtilMatches;
import com.zcx.helper.util.UtilToast;

/**
 * Created by Administrator on 2016/8/2.
 */
public class FeedBackActivity extends BaseActivity implements View.OnClickListener {

    @BoundView(R.id.feedback_content_et) private EditText feedback_content_et;
    @BoundView(R.id.feedback_phonenum_et) private EditText feedback_phonenum_et;
    @BoundView(R.id.feedback_submit_bt) private TextView feedback_submit_bt;

    private FeedBackSetGet feedBackSetGet = new FeedBackSetGet(new AsyCallBack<String>(){
        @Override
        public void onSuccess(String toast, int type, String s) throws Exception {

            UtilToast.show(FeedBackActivity.this, toast);

            finish();

        }

        @Override
        public void onFail(String toast, int type) throws Exception {

            UtilToast.show(FeedBackActivity.this, toast);

        }
    });

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_feedback);

        setBackTrue();

        setTitleName(getResources().getString(R.string.feedback_title_text));

        setRightName(getString(R.string.feedback_right_title_update_text), R.color.white, this);

        feedback_submit_bt.setOnClickListener(this);

    }

    @Override
    public void onClick(View view) {

        switch (view.getId()) {

            case R.id.title_right_ll:

                startActivity(new Intent(this, FeedBackDetailActivity.class));

                break;

            case R.id.feedback_submit_bt:

                final String contentStr = feedback_content_et.getText().toString().replace(" ","");
                final String phonenumStr = feedback_phonenum_et.getText().toString().replace(" ", "");

                if (TextUtils.isEmpty(contentStr)){

                    MyToast.show(context, getString(R.string.warning_please_fill_feedback_content_text), Toast.LENGTH_LONG);

                    return;

                } else if (TextUtils.isEmpty(phonenumStr)) {

                    MyToast.show(context, getString(R.string.warning_please_fill_phone_text), Toast.LENGTH_LONG);

                    return;
                } else if (!UtilMatches.checkMobile(phonenumStr)){

                    MyToast.show(context, getString(R.string.warning_please_fill_true_phone_text), Toast.LENGTH_LONG);

                    return;
                }

                new WarnningDialog(context, getString(R.string.feedback_submit_text)) {

                    @Override
                    protected void onConfirm() {

                        feedBackSetGet.phone = phonenumStr;
                        feedBackSetGet.content = contentStr;
                        feedBackSetGet.user_id = BaseApplication.BasePreferences.readUserId();

                        feedBackSetGet.execute(FeedBackActivity.this);

                    }


                }.show();

                break;

        }

    }
}
